package com.huarui.part.action;

import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.ewaf.framework.action.BaseAction;

import com.huarui.part.model.PartUpload;
import com.huarui.part.service.PartUploadService;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

public class PartUploadAddAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3295903010652284640L;

	private static final Logger logger = Logger
			.getLogger(PartUploadAddAction.class);

	private PartUploadService partUploadService;

	private Map<String, Object> resultMap;

	private String jsonData;

	public String newPartSave() {

		PartUpload partUpload = (PartUpload) JSONObject.toBean(
				JSONObject.fromObject(jsonData), PartUpload.class);

		SessionMessage sm = UserHolder.getCurrentSessionMessage();

		partUpload.setCompanyId(sm.getCompanyId());
		partUpload.setCompanyName(sm.getCompanyName());
		partUpload.setCode(partUpload.getCode().trim());
		partUpload.setBrand(partUpload.getBrand().trim());
		partUpload.setCarModel(partUpload.getCarModel().trim());
		partUpload.setName(partUpload.getName().trim());
		partUpload.setNameEn(partUpload.getNameEn().trim());
		resultMap = partUploadService.save(partUpload);

		return JSON;
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public String getJsonData() {
		return jsonData;
	}

	public void setJsonData(String jsonData) {
		this.jsonData = jsonData;
	}

	public void setPartUploadService(PartUploadService partUploadService) {
		this.partUploadService = partUploadService;
	}

}
